package activiti2;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.List;

/**
 * 并行网关
 */
public class BingXingWangGuan {

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    /**
     *
     * 部署和启动流程
     *
     */
    @Test
    public void deployementAndStartProcess(){
        //部署   act_ru_execution  部署ID37501
        Deployment deployment = processEngine.getRepositoryService()
                .createDeployment()
                .addClasspathResource("diagrams/bingxingwangguan.bpmn")
                .name("并行网关Demo")
                .deploy();
        System.out.println("部署ID"+deployment.getId());
        //启动  act_ru_task
        //流程实例ID：40001
        //流程定义的ID：myProcess_5:1:37504
        ProcessInstance pi = processEngine.getRuntimeService().
                startProcessInstanceByKey("myProcess_5");//使用流程定义的key的最新版本启动流程
        System.out.println("流程实例ID："+pi.getId());
        System.out.println("流程定义的ID："+pi.getProcessDefinitionId());

    }

    /**
     *
     * 查询个人任务
     *
     */
    @Test
    public void findPersonalTaskList(){
        //任务办理人
        String assignee = "商家";
        List<Task> list = processEngine.getTaskService()
                .createTaskQuery()
                .taskAssignee(assignee)
                .list();
        
        if(list!=null && list.size()>0){
            for (Task task:list) {
                System.out.println("任务ID："+task.getId());
                System.out.println("任务的办理人："+task.getAssignee());
                System.out.println("任务名称："+task.getName());
                System.out.println("任务的创建时间："+task.getCreateTime());
                System.out.println("流程实例ID："+task.getProcessInstanceId());
                System.out.println("#########################################");
            }
        }
    }

    /**
     * 完成任务
     */
    @Test
    public void completeTask(){
        String taskId = "47502";
        processEngine.getTaskService().complete(taskId);
        System.out.println("完成任务："+taskId);
    }


}
